<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="方法名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="exeFunctionName">
              <a-input v-model="model.exeFunctionName" placeholder="请输入方法名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="方法中文名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="exeFunctionNameCn">
              <a-input v-model="model.exeFunctionNameCn" placeholder="请输入方法中文名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="方法目标对象类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="exeTargetObjType">
              <a-input v-model="model.exeTargetObjType" placeholder="请输入方法目标对象类型"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="参数格式样式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="exeFunctionParamFormart">
              <a-input v-model="model.exeFunctionParamFormart" placeholder="请输入参数格式样式"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="前置方法id，起始是start" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="exeFunctionPrepositionId">
              <a-input v-model="model.exeFunctionPrepositionId" placeholder="请输入前置方法id，起始是start"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="方法描述" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="exeFunctionDescription">
              <a-input v-model="model.exeFunctionDescription" placeholder="请输入方法描述"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否启用：1是(启用) 0否(停用)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="izOpen">
              <j-dict-select-tag v-model="model.izOpen" dict-code="iz_open"></j-dict-select-tag>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="删除状态：1是(已删除) 0否(正常)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="delFlag">
              <j-dict-select-tag v-model="model.delFlag" dict-code="del_flag"></j-dict-select-tag>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'TaskExeFunctionForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
          izOpen: 1,
          delFlag: 0,
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           exeFunctionName: [
              { required: true, message: '请输入方法名称!'},
           ],
           exeFunctionNameCn: [
              { required: true, message: '请输入方法中文名称!'},
           ],
           tenantId: [
              { required: true, message: '请输入租户ID!'},
           ],
        },
        url: {
          add: "/upgrade/taskExeFunction/add",
          edit: "/upgrade/taskExeFunction/edit",
          queryById: "/upgrade/taskExeFunction/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>